Since the answer is mysteriously zero, you should suspect that one of the variable names has been changed. The name COSTS in the PRINT statement is not the same as COST in the third statement.
' Cost of renting a car
' $26.59 per day
' 31 cents per mile, plus
' 3 days and 253 miles
'
LET DAYS = 3
LET MILES = 253
LET COST = 26.59 * DAYS + 0.31 * MILES
PRINT "Cost is", COSTS
END ^
wrong
Remember that a variable is a small amount of computer memory that has been given name. The contents of computer memory can be changed. In your program you can do this by using a LET statement with a variable that already has something in it. Look at the following program:
' Changing the contents of a variable ' LET NUMBER = 23.5 ' create NUMBER, put 23.5 into it PRINT "First", NUMBER ' look in NUMBER to find a value to print LET NUMBER = 45.1 ' put 45.1 into NUMBER (erasing the 23.5) PRINT "Second", NUMBER ' look in NUMBER to find a value to print END
Execution starts with the first statement, the first LET
statement.
This is the first time NUMBER
is used,
so memory is found for it.
Then 23.5 is put into it.
into it:
|
Now the first PRINT
statement executes.
It looks into NUMBER
, finds
23.5, and prints that to the screen.
The value in NUMBER
has not changed.
Does a LET
statement always find new memory for
a variable?